import { parseTimeDot } from "@/utils/utils.js"
import { getComment } from "@/static/js/message.js"
import { checkQuiz } from "@/static/js/my.js";

export default {
  data() {
    return {
      parseTimeDot,
      page: 1,
      list: [],
      noMore: 'loadmore', // loading / noMore

      activeStyle: {
        'font-size': '38rpx',
        'font-weight': '500',
        'color': '#1C87F3',
      },
      inactiveStyle: {
        'font-size': '38rpx',
        'font-weight': '500',
        'color': 'rgba(0,0,0,0.8)',
      },
      isLoading: false,
    }
  },
  onLoad() {
    this.isLoading = true
    this.getComment()
  },

  onPullDownRefresh() {
    this.isLoading = true
    this.list = []
    this.page = 1
    this.noMore = 'loadmore'
    this.getComment()
  },
  onReachBottom() {
    if (this.noMore == 'noMore') return
    this.page++
    this.getComment()
  },
  methods: {
    async getComment() {
      this.isLoading = true;
      //获取当前年份
      const currentDate = new Date();
      const currentYear = currentDate.getFullYear();
      this.noMore = 'loading'
      const res = await getComment({
        page: this.page,
        pagesize: 10
      })
      if (res.code == 1) {
        if (res.data.length == 0 || res.data.length < 10) {
          this.noMore = 'noMore'
        } else {
          this.noMore = 'loadmore'
        }
        let list = res.data
        list.forEach(e => {
          const updateTime = new Date(e.updatetime * 1000);
          const updateYear = updateTime.getFullYear();
          if (currentYear === updateYear) {
            e.updatetime = parseTimeDot(e.updatetime, '{m}-{d} {h}:{i}');
          } else {
            e.updatetime = parseTimeDot(e.updatetime, '{y}-{m}-{d} {h}:{i}');
          }
        });
        this.list.push(...list)
        uni.stopPullDownRefresh()
      }
      this.isLoading = false;
    },


    go(url) {
      uni.navigateTo({
        url: url
      })
    },

    async goCheck(item) {
      const res = await checkQuiz({
        quiz_id: item.quiz_id,
      });
      if (res.code == 1) {
        uni.navigateTo({
          url: '/quiz/askInfo/index?id=' + item.quiz_id
        })
      } else if (res.code == 3) {
        uni.showToast({
          title: res.msg,
          icon: "none",
        });
      }

    }

  }
}